﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainProject.Quanlychiphisua
{
    public partial class Nhapchiphisua : Form
    {
        public Nhapchiphisua()
        {
            InitializeComponent();
            loaddata();
        }

        private void loaddata()
        {
            QLXT_DBDataContext db = new QLXT_DBDataContext();
            cmb_Idxe.DataSource = from p in db.XEs select p;
            cmb_Idxe.DisplayMember = "BIENSO";
            cmb_Idxe.ValueMember = "IDXE";
            cmb_Idxe.SelectedIndex = 1;

            cmb_Tuyensua.DataSource = from p in db.TUYENs select p;
            cmb_Tuyensua.ValueMember = "IDTUYEN";
            cmb_Tuyensua.DisplayMember = "TENTUYEN";
            cmb_Tuyensua.SelectedIndex = 1;

            txt_Nguyennhan.Text = "";
            txt_Gara.Text = "";
            txt_Tongtien.Text = "";

            date_Ngaysua.Value = DateTime.Now;
            rtxt_Ghichu.Text = "";
        }

        private void bnt_Nhap_Click(object sender, EventArgs e)
        {
            QLXT_DBDataContext qlxt_db = new QLXT_DBDataContext();

            try
            {
                CHIPHISUA tt = new CHIPHISUA();

                tt.GARA = txt_Gara.Text;
                tt.NGUYENNHAN = txt_Nguyennhan.Text;
                tt.GHICHU = rtxt_Ghichu.Text;
                tt.TONGTIEN = double.Parse(txt_Tongtien.Text);
                tt.TUYEN = (int)cmb_Tuyensua.SelectedValue;
                tt.IDXE = (int)cmb_Idxe.SelectedValue;
                tt.NGAYSUA = date_Ngaysua.Value;

                qlxt_db.CHIPHISUAs.InsertOnSubmit(tt);
                qlxt_db.SubmitChanges();
                DialogResult re = MessageBox.Show(@"Nhập liệu thành công. Bạn có muốn nhập tiếp không?", @"Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (re == DialogResult.Yes)
                    loaddata();
                else
                    this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Vui lòng nhập thông tin chính xác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void bnt_Lamlai_Click(object sender, EventArgs e)
        {
            loaddata();
        }

        private void bnt_Thoat_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
